package Homework;

import java.util.*;

/**
 * @author DCSGO
 * @version 1.0
 * 按要求完成下列任务
 * 1)使用HashMap类实例化一个Map类型的对象m，键(String)和值(int)分别用于存储员工的姓名和工资
 * 存入数据如下:jack—650元; tom—1200元; smith——2900元;
 * 2)将jack的工资更改为2600元
 * 3)为所有员工工资加薪100元;
 * 4)遍历集合中所有的员工
 * 5)遍历集合中所有的工资
 */

@SuppressWarnings({"all"})
public class Homework03 {
    public static void main(String[] args) {
        Map m = new HashMap();
        m.put("jack", 650);
        m.put("tom", 1200);
        m.put("smith", 2900);

        System.out.println(m);
        //{tom=1200, smith=2900, jack=650}

        //2)将jack的工资更改为2600元
        m.put("jack", 2600);
        System.out.println(m);
        //{tom=1200, smith=2900, jack=2600}

        //3)为所有员工工资加薪100元;
        /*Set set = m.entrySet();
        Iterator iterator = set.iterator();
        while (iterator.hasNext()) {
            Map.Entry employee = (Map.Entry) iterator.next();
            employee.setValue((Integer) employee.getValue() + 100);
        }*/
        Set keySet1 = m.keySet();
        for (Object key : keySet1) {
            m.put(key, (Integer) m.get(key) + 100);
        }
        System.out.println(m);
        //{tom=1300, smith=3000, jack=2700}

        //4)遍历集合中所有的员工
        Set keySet = m.keySet();
        for (Object key : keySet) {
            System.out.print(key + "-" + m.get(key) + " ");
        }
        //tom-1300 smith-3000 jack-2700

        System.out.println();
        //5)遍历集合中所有的工资
        Collection values = m.values();
        for (Object salary : values) {
            System.out.print(salary + " ");
        }
        //1300 3000 2700
    }
}

class Employee {
    String name;
    int salary;
}

